<html>
<HEAD>
<script language="javascript"> 
<!--
var backup_window = null;
var state = 'none'; 

function showhide(layer_ref) { 

if (state == 'block') { 
state = 'none'; 
} 
else { 
state = 'block'; 
} 
if (document.all) { //IS IE 4 or 5 (or 6 beta) 
eval( "document.all." + layer_ref + ".style.display = state"); 
} 
if (document.layers) { //IS NETSCAPE 4 or below 
document.layers[layer_ref].display = state; 
} 
if (document.getElementById &&!document.all) { 
hza = document.getElementById(layer_ref); 
hza.style.display = state; 
} 
} 

//-->
</SCRIPT>
</HEAD>
<body>
<DIV style="font-family:Arial;width=90%">
<?php include("database_inc.php"); ?>
<?php 

error_reporting('IGNORE_REPEATED_ERRORS');

    $client_number = $_POST["client_number"]; 
    //echo "Client_Number: ".$client_number."<BR>";
    $staff_operator = addslashes($_POST["staff_operator"]);
    //echo "Staff_operator: ".$staff_operator."<BR>";
    $call_date = $_POST["call_date"];
    //echo "Call_date: ".$call_date."<BR>";

    $unreachable = $_POST["unreachable"];
    //echo "Unreachable: ".$unreachable."<BR>";
    $unreachable_other = addslashes($_POST["unreachable_other"]);
    //echo "Unreachable_other: ".$unreachable_other."<BR>";
    $unreachable_taxonomy = $_POST["unreachable_taxonomy"];
    //echo "Unreachable_taxonomy: ".$unreachable_taxonomy."<BR>";

    $need_met = $_POST["need_met"];
    //echo "Need_met: ".$need_met."<BR>";
    $need_was_met = $_POST["need_was_met"];
    //echo "Need_met: ".$need_was_met."<BR>";
    $needmet_description = $_POST["needmet_description"];
    $need_taxonomy = $_POST["need_taxonomy"];
    //echo "Need_taxonomy: ".$need_taxonomy."<BR>";

    $agency_name_1 = $_POST["agency_name_1"];
    //echo "Agency_Name_1: ".$agency_name_1."<BR>";
    $agency_taxonomy_1 = $_POST["agency_taxonomy_1"];
    //echo "Agency_taxonomy_1: ".$agency_taxonomy_1."<BR>";

    $agency_contacted_1 = $_POST["agency_contacted_1"];
    //echo "Agency_contacted_1: ".$agency_contacted_1."<BR>";
    $agency_contacted_other_1 = $_POST["contactedother1"];
    //echo "Agency_contacted_other_1: ".$agency_contacted_other_1."<BR>";
    $agency_contact_time_1 = $_POST["agency_contacted_time_1"];
    //echo "Agency_contacted_time_1: ".$agency_contacted_time_1."<BR>";
    $agency_assistance_1 = $_POST["agency_assistance_1"];
    //echo "Agency_assistance_1: ".$agency_assistance_1."<BR>";
    $agency_explanation_1 = addslashes($_POST["agency_assistance_explanation_1"]);
    //echo "Agency_explanation_1: ".$agency_explanation_1."<BR>";
    $agency_treated_1 = $_POST["agency_treated_1"];
    //echo "Agency_treated_1: ".$agency_treated_1."<BR>";


    $agency_name_2 = $_POST["agency_name_2"];
    //echo "Agency_Name_2: ".$agency_name_2."<BR>";
    $agency_taxonomy_2 = $_POST["agency_taxonomy_2"];
    //echo "Agency_taxonomy_2: ".$agency_taxonomy_2."<BR>";
    $agency_contacted_2 = $_POST["agency_contacted_2"];
    //echo "Agency_contacted_2: ".$agency_contacted_2."<BR>";
    $agency_contacted_other_2 = $_POST["contactedother2"];
    //echo "Agency_contacted_other_2: ".$agency_contacted_other_2."<BR>";
    $agency_contact_time_2 = $_POST["agency_contacted_time_2"];
    //echo "Agency_contacted_time_2: ".$agency_contacted_time_2."<BR>";
    $agency_assistance = $_POST["agency_assistance"];
    //echo "Agency_assistance: ".$agency_assistance."<BR>";
    $agency_assistance_2 = $_POST["agency_assistance_2"];
    //echo "Agency_assistance_2: ".$agency_assistance_2."<BR>";
    $agency_explanation_2 = addslashes ($_POST["agency_assistance_explanation_2"]);
    //echo "Agency_explanation_2: ".$agency_explanation_2."<BR>";
    $agency_treated_2 = $_POST["agency_treated_2"];
    //echo "Agency_treated_2: ".$agency_treated_2."<BR>";

    $appropriate = $_POST["appropriate"];
    //echo "Appropriate: ".$appropriate."<BR>";
    $refer = $_POST["refer"];
    //echo "Refer: ".$refer."<BR>";
    $comments = addslashes($_POST["comments"]);
    //echo "Comments: ".$comments."<BR>";


    $client_check = 0;
    if((strlen($client_number)>0)&&(strlen($call_date)>0)){
        $client_check = 1;    	
    }else{
	echo "Please review the input and be sure to enter a client number and call date.<BR>";
    }
    
    
    mysql_connect ($db_conn_address, $db_conn_username, $db_conn_password) or die ('Error: ' . mysql_error());
    mysql_select_db($db_QA_database);

    $insert_caller_query = "INSERT INTO Caller (Client_Number, Call_Date) VALUES ('".$client_number."', '".$call_date."');";

	 mysql_query($insert_caller_query) or die ('Error saving client information to the database:'.$insert_caller_query."<BR>");
	 $client_reference_number = mysql_result(mysql_query("Select LAST_INSERT_ID();"),0);

         $insert_unreachable_query = "INSERT INTO Needs (Caller_Reference, Met, Taxonomy) VALUES('".$client_reference_number."', '".$need_was_met."', '".$unreachable_taxonomy."');";
         mysql_query($insert_unreachable_query);

         $insert_agency_query = "INSERT INTO AgencyFeedback (Caller_Reference, Taxonomy, Assistance) VALUES('".$client_reference_number."', '".$unreachable_taxonomy."', '".$agency_assistance."');";
         mysql_query($insert_agency_query);



	 echo "Database updated with client information: ".$client_number.", ".$call_date.".<BR>";
	 echo "New Client Record in the QA system number ".$client_reference_number.".<BR>";
         $insert_unreachable_query = "INSERT INTO 211Feedback (Caller_Reference, Appropriate, Refer) VALUES('".$client_reference_number."', '".$appropriate."', '".$refer."');";
         mysql_query($insert_unreachable_query);
         echo "211 Service feedback has been saved.<BR>";

?><BR>

<BR>

<div id="input" style="display:block;border:thin solid black;background-color: #AAFFAA;width=40%">
<p><a href="newinput.php"> Enter Another Call</a></p> 
</div>


<BR>
 
<div id="exit" style="display:block;border:thin solid black;background-color: #FFAAAA;width=40%">
<p><a href="#" onclick="showhide('thanks');backup_window=(window.open('./backup_data.php','BackupWindow','width=50,height=50,toolbar=0,menubar=0,status=0,scrollbars=0,resizable=1')).blur();"> Done Entering Calls </a></p>
</div>

<BR><BR>
<div id="thanks" style="display:none;border:thin solid black;background-color: #EEEEEE;width=30%">
<p>Thank You!  Your work has just been backed up.</p>
</div>

<BR><BR>
<a href="new_purge_record.php?client_reference_number=<?php echo $client_reference_number; ?>">click here to purge the record just entered due to a mistake</A>

<BR><BR>
<A href="http://211qa.uservoice.com/pages/34599-general?lang=en&utm_campaign=Widgets&utm_content=tab-widget&utm_medium=widget&utm_source=211qa.uservoice.com" target="_Top">click here to visit the feedback forum where you can provide bug reports, enhancement requests and support questions!</A>


</DIV>
</body>
</html>